package org.sevaapp.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sevaapp.domain.Referral;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

@Controller
public class ReferralController extends BaseReferralController {

	private static final Log log = LogFactory.getLog(ReferralController.class);

	/**
	 * Validation method implementation.
	 */
	public boolean validate(Model model,Referral inputData) {
		log.debug("validate() method called.");
		
		//check status of applicant
		//If the qualification status of the applicant is NOT APPROVED or EXPIRED, 
		// issue "Your membership status is : STATUS" "Application for referral will 
		// not be accepted" Please contact SEVA representative for further information.
		String msg;
		
		if ((inputData.getApplicant().getStatus() != null ) && (inputData.getApplicant().getStatus().equalsIgnoreCase("NOT APPROVED") || inputData.getApplicant().getStatus().equalsIgnoreCase("EXPIRED"))){
			msg = "Your membership status is : " + inputData.getApplicant().getStatus() + ". Application for referral will not be accepted. Please contact SEVA representative for further information.";
			model.addAttribute("referralMessage",msg);
		}
		  
		//If a referral has already been issued for the applicant and the current status 
		//of the Applicant is not QUALIFIED then issue "You have already been granted a free 
		//referral. Please submit necessary documents to qualify for additional referrals.  
		 if ((inputData.getApplicant().getStatus() != null ) && inputData.getApplicant().getStatus().equalsIgnoreCase("QUALIFIED")){
			 msg = "You have already been granted a free referral. Please submit necessary documents to qualify for additional referrals.";
			 model.addAttribute("referralMessage",msg);
		 }

		return true;
	}

}
